home *** CD-ROM | disk | FTP | other *** search
- { This is an attempt to duplicate the program 'Aquarium,' which takes up a
- whopping 35K of disk space. My guess is that it could be done in less room.
- Also, a good chance to learn about PICT resources & CopyBits calls.
- The general gist is thus: 1) Open the ScrapBook file (or whichever one
- has the fish PICT in it); 2) Open a window over the entire screen;
- 3) Move the fish around, bouncing it off of the window edges;
- 4) Exit when the user presses a key or clicks the mouse button.
-
- }
-
- PROGRAM Aquarium1;
-
- {$U-} {Turn normal Unit usage off}
- {$R-} {Range checking off}
- {$T APPLAqrm} {Type & creator}
-
- uses MemTypes, QuickDraw, OSIntf, ToolIntf;
-
-
-
- VAR {Globals}
-
- indx,
- MaxWidth,
- MaxHeight,
- MinWidth,
- MinHeight,
- hdist,
- vdist: integer;
- FishRect,
- r,
- bounds: rect; {for setting up the screen}
- WhichFish,
- visible: boolean;
- theWindP: WindowPtr;
- anevent: eventRecord;
- myPort: grafPort;
-
- a: boolean;
- thePoint: point;
- PicHandle1,
- PicHandle2,
- PicHandle3,
- PicHandle4: PicHandle;
-
-
-
-
- procedure debugger; inline $A9FF; {crash into the debugger, not bomb box}
-
-
-
- procedure crash;
- begin
- debugger;
- end;
-
-
-
- procedure SetUpScreen;
- begin
- OpenPort(@myPort);
- bounds:= screenbits.bounds;
- theWindP:= NewWindow( nil, bounds, '', visible, rDocProc,
- Pointer(-1), True, 0);
- FillRect(bounds, white);
- end;
-
-
- { ---------------------------------- end SetUpScreen --------------- }
-
-
-
- procedure Init;
- begin
- MoreMasters;
- InitGraf(@thePort);
- Randseed:= TickCount;
- InitFonts;
- FlushEvents(Everyevent, 0);
- InitWindows;
- {InitMenus;} {We don't use them, we don't want to see them}
- TEInit;
- InitDialogs(@crash);
- InitCursor;
- PenNormal;
- visible:= true;
- SetUpScreen; {get the port}
- MaxWidth := MyPort.portrect.right;
- MaxHeight := MyPort.portrect.bottom;
- MinWidth := MyPort.portrect.left;
- MinHeight := MyPort.portrect.top;
- end;
-
-
-
- procedure ResFork;
- VAR
- a: boolean;
- TheError,
- TheRefNum: integer;
- anEvent: EventRecord;
- TheFileName: String[63];
- BEGIN
- a := false;
- (* theRefNum := OpenResFile( 'XAquarium'); *) {RAM only}
- (* *) theRefNum := CurResFile; (* to disk ONLY *)
- {get our appl rsrc file ref# to use}
- TheError:= ResError;
- If TheError <> noErr then
- BEGIN
- Sysbeep(5);
- MoveTo(400, 18);
- DrawString(' The file was not found. ');
- repeat
- a := GetNextEvent( keyDownMask + mDownMask, anEvent);
- until a;
- ExitToShell;
- END {if};
- END;
-
-
-
- PROCEDURE GetPic;
- var
- thePic1,
- thePic2,
- thePic3,
- thePic4 :Handle;
- BEGIN
- thePic1 := GetResource('PICT', -32760); {rh, reg}
- thePic2 := GetResource('PICT', -32762); {rh, up}
- thePic3 := GetResource('PICT', -32763); {lh, reg}
- thePic4 := GetResource('PICT', -32761); {lh, up}
- {convert all 4 'Handles' to 'PicHandles'}
- PicHandle1 := picHandle(thePic1);
- PicHandle2 := picHandle(thePic2);
- PicHandle3 := picHandle(thePic3);
- PicHandle4 := picHandle(thePic4);
- if PicHandle1 = NIL then
- BEGIN
- SysBeep( 5);
- ExitToShell;
- END;
- if PicHandle2 = NIL then
- BEGIN
- SysBeep( 5);
- ExitToShell;
- END;
- if PicHandle3 = NIL then
- BEGIN
- SysBeep( 5);
- ExitToShell;
- END;
- if PicHandle4 = NIL then
- BEGIN
- SysBeep( 5);
- ExitToShell;
- END;
- END;
-
-
-
- FUNCTION SetHDist: integer;
- VAR
- newx: integer;
- BEGIN
- newx:= abs(random) mod 7 * 2;
- if newx = 0 then newx:= newx + 2;
- SetHDist:= newx;
- END;
-
-
-
- FUNCTION SetVDist: integer;
- VAR
- newx: integer;
- BEGIN
- newx:= abs(random) mod 4 * 2;
- if newx = 0 then newx:= newx + 2;
- SetVDist:= newx;
- END;
-
-
-
- PROCEDURE TestEdges;
- BEGIN
- If FishRect.left >= MaxWidth - 30 then hdist:= -SetHDist; {neg}
- If FishRect.top >= MaxHeight - 16 then vdist:= -SetVDist; {neg}
- If FishRect.right <= MinWidth + 30 then hdist:= SetHDist; {pos}
- If FishRect.bottom <= MinHeight + 16 then vdist:= SetVDist; {pos}
- END;
-
-
-
- PROCEDURE DrawTheFish( VAR FishRect: rect);
- VAR
- TitlePoint,
- TitlePoint1: point;
- BEGIN
- OffSetRect(Fishrect, hDist, vDist); {move the actual rect coords}
- IF WhichFish then {draw fish on screen}
- if hdist > 0 then {right-going fish}
- DrawPicture( PicHandle1, FishRect) {rh reg}
- else {left-going fish}
- DrawPicture( PicHandle3, FishRect) {lh reg}
- ELSE
- if hdist > 0 then
- DrawPicture( PicHandle2, FishRect) {rh up}
- else
- DrawPicture( PicHandle4, FishRect); {lh up}
- WhichFish := NOT WhichFish;
- TitlePoint.h := 224;
- TitlePoint.v := 20;
- TitlePoint1.h := 290;
- TitlePoint1.v := 20;
- IF NOT( PtInRect( TitlePoint, FishRect) OR PtInRect( TitlePoint1, FishRect))
- THEN
- BEGIN
- MoveTo(225, 18);
- TextFont(0); {Chicago}
- TextSize(12);
- TextFace([underline]);
- DrawString('Aquarium');
- END; {if IN TitleRect, don't draw}
- END;
-
-
-
-
-
-
- BEGIN {------------- MAIN PROGRAM LOOP ---------------}
- Init;
- HideCursor;
- TextFont(1);
- TextSize(9);
- ResFork; {open the Rsrc file}
- GetPic; {get the fish PICT resources into handles}
- hDist := SetHDist;
- vDist := SetVDist;
- WhichFish := true;
- SetRect( FishRect, 1, 1, 302, 163); {starting fish place}
- a := false;
-
-
- while not a DO
- begin
- TestEdges;
- DrawTheFish( FishRect);
- a:=getNextEvent(mDownMask + keyDownMask, anEvent);
-
- {we've now gotten a key or mouse event, so end}
-
- END; {while not A...}
- ShowCursor;
- END.
-